﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Acms.WebControls
{
    public class ActionButton : LinkButton
    {
        public enum ActionButtonIcons
        {
            None,
            Publish,
            Add,
            Edit,
            Cancel,
            Save,
            UpDown,
            Clear,
            AddChild,
            AddSibling,
            Copy,
            Position,
            Ready
        }

        public ActionButtonIcons Icon{ get; set; }

        private string GetCssClass()
        {
            string iconCssClass = "";
            if(Icon != ActionButtonIcons.None)
            {
                iconCssClass = string.Format("ab{0}", Icon.ToString());
            }
            var tmp = string.Format("actionBtn {0} {1}", iconCssClass, this.CssClass).Trim();
            return tmp;
        }

        public string NavigateUrl;

        protected override void Render(HtmlTextWriter writer)
        {

            writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID);
            if(!string.IsNullOrEmpty(this.NavigateUrl))
                writer.AddAttribute(HtmlTextWriterAttribute.Href, Page.ResolveUrl(NavigateUrl));
            else
                writer.AddAttribute(HtmlTextWriterAttribute.Href, Page.ClientScript.GetPostBackClientHyperlink(this, null));
            writer.AddAttribute(HtmlTextWriterAttribute.Class, GetCssClass());
            writer.AddAttribute(HtmlTextWriterAttribute.Title, this.ToolTip);
            writer.RenderBeginTag(HtmlTextWriterTag.A);

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "tl");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "tr");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "bl");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "br");
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            writer.RenderBeginTag(HtmlTextWriterTag.Span);
            writer.Write(Text);
            writer.RenderEndTag();//Span

            writer.RenderEndTag();//Div br
            writer.RenderEndTag();//Div bl
            writer.RenderEndTag();//Div tr
            writer.RenderEndTag();//Div tl

            writer.RenderEndTag();//A
            /*
            <a>
                <div class="tl">
                    <div class="tr">
                        <div class="bl">
                            <div class="br">
                                <span>Save</span>
                            </div>
                        </div>
                    </div>
                </div>
            </a>
            */
        }
    }
}
